var inival = 0; // Initialise starting element number
var groupnr = 0;

// Call this function to add a textarea
function addTextArea() {
	var newArea = add_New_Element_area();
	var htcontents = "<td colspan='2'><center><textarea name='observatii' cols=70 rows=3>Observatii</textarea></center></td>";
	document.getElementById(newArea).innerHTML = htcontents;
}

// Call this function to add textbox
function addTextBox() {
	var newArea = add_New_Element();
	groupnr += 1;
	var index = 1;
	var htcontents = "<tr><td colspan='2'>Nume Produs: </td><td><input type='text' name='"
			+ groupnr
			+ "_"
			+ index++
			+ "' required='required' id='autocompleteinput"
			+ groupnr
			+ "'/></td>";

	document.getElementById(newArea).innerHTML = htcontents;

}
function add_New_Element() {
	inival = inival + 1; // Increment element number by 1
	var ni = document.getElementById('area');
	var newdiv = document.createElement('tr'); // Create dynamic element
	var divIdName = 'my' + inival + 'Div';
	newdiv.setAttribute('id', divIdName);
	ni.appendChild(newdiv);
	return divIdName;
}

function removeElement() {
	var d = document.getElementById('area');
	var olddiv = document.getElementById("my" + inival + "Div");
	d.removeChild(olddiv);
	if (inival != 0) {
		inival--;
	}
	if (groupnr != 0) {
		groupnr--;
	}

}
